//
//  RCBaseViewController.m
//  baseUIkitDemo
//
//  Created by kabu on 2017/9/12.
//  Copyright © 2017年 youedata. All rights reserved.
//

#import "RCBaseViewController.h"

@interface RCBaseViewController ()

@end

@implementation RCBaseViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor=[UIColor whiteColor];
    // Do any additional setup after loading the view.
}
////设置标题文字颜色
//-(void)setNaviTitleColor:(UIColor*)color fontName:(NSString*)fontName size:(float)size{
//    if (!color) {
//        color=[UIColor whiteColor];
//    }
//    UIFont *font=[UIFont boldSystemFontOfSize:size];
//    if (fontName) {
//        font=[UIFont fontWithName:fontName size:size];
//    }
//    
//    NSDictionary *dict=[[NSDictionary alloc]initWithObjectsAndKeys:color,NSForegroundColorAttributeName,font,NSFontAttributeName, nil];
//    [self.navigationController.navigationBar setTitleTextAttributes:dict];
//}
/**
 设置navigation bar 可见
 
 @param hiden 隐藏或者显示
 */
-(void)hidenNavigationBar:(BOOL)hiden{
    [self.navigationController setNavigationBarHidden:hiden];
}
////设置navi背景图片或者颜色
//-(void)setNaviBarBackColorWithImage:(UIImage*)image orColor:(UIColor*)color{
//    self.navigationController.navigationBar.translucent=NO;
//    if (!image) {
//        [self.navigationController.navigationBar setBarTintColor:color];
//    }else{
////        [self.navigationController.navigationBar setBarTintColor:[UIColor colorWithPatternImage:image]];
////        [self.navigationController.navigationBar setBackgroundImage:image forBarMetrics:UIBarMetricsDefault];
//        [self.navigationController.navigationBar setBackgroundImage:image forBarPosition:UIBarPositionAny barMetrics:UIBarMetricsDefault];
//    }
//
//}
-(void)createLeftBackWithString:(NSString*)title img:(UIImage*)img{
    [self createLeftBarButtonCustomItem:title Img:img Select:@"backPressed:" Margin:@0 Rect:CGRectMake(0, 0, 44, 44)];
}
-(void)backPressed:(UIButton*)sender{
    if (self.navigationController) {
        [self.navigationController popViewControllerAnimated:YES];
    }else{
        [self dismissViewControllerAnimated:YES completion:^{
            //
        }];
    }
}
-(void)createLeftBarButtonCustomItem:(NSString *)content Img:(UIImage *)img Select:(NSString*)method Margin:(NSNumber*)margin Rect:(CGRect)bound{
    UIButton *leftBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [leftBtn setFrame:bound];
    if (content) {
        [leftBtn setTitle:content forState:UIControlStateNormal];
        [leftBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    }
    if (img) {
        [leftBtn setImage:img forState:UIControlStateNormal];
    }
    SEL mo = NSSelectorFromString(method);
    [leftBtn addTarget:self action:mo forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem * backItem = [[UIBarButtonItem alloc]initWithCustomView:leftBtn];
    self.navigationItem.leftBarButtonItem=backItem;
}

-(void)createRightBarButtonCustomItem:(NSString *)content Img:(UIImage *)img Select:(NSString*)method Margin:(NSNumber*)margin Rect:(CGRect)bound{
    UIButton *rightBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [rightBtn setFrame:bound];
    if (content) {
        [rightBtn setTitle:content forState:UIControlStateNormal];
        [rightBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    }
    if (img) {
        [rightBtn setImage:img forState:UIControlStateNormal];
    }
    SEL mo = NSSelectorFromString(method);
    [rightBtn addTarget:self action:mo forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem * backItem = [[UIBarButtonItem alloc]initWithCustomView:rightBtn];
    self.navigationItem.rightBarButtonItem=backItem;
}
-(void)borderView:(UIView*)view cornerRadius:(float)cornerRadius borderColor:(CGColorRef)borderColor{
    if (!borderColor) {
        borderColor=[UIColor clearColor].CGColor;
    }
    view.layer.masksToBounds=YES;
    view.layer.cornerRadius=cornerRadius;
    view.layer.borderColor=borderColor;
}
- (UIButton*)createBtnInFrame:(CGRect)rect sel:(NSString*)selStr atView:(UIView*)aView{
    UIButton *btn=[UIButton buttonWithType:UIButtonTypeCustom];
    [btn setFrame:rect];
    SEL sel=NSSelectorFromString(selStr);
    [btn addTarget:self action:sel forControlEvents:UIControlEventTouchUpInside];
    [aView addSubview:btn];
    return btn;
}

- (UIViewController*)viewControllerWithMainStoryboardId:(NSString*)storyboardId{
    UIStoryboard *storyboard=[self storyBoardWithName:@"Main" bundle:nil];
    return [self viewControllerWithStoryboardId:storyboardId storyboard:storyboard];
}
- (UIViewController*)viewControllerWithStoryboardId:(NSString*)storyboardId storyboard:(UIStoryboard*)storyboard{
    UIViewController *vc=[storyboard instantiateViewControllerWithIdentifier:storyboardId];
    return vc;
}

-(UIStoryboard*)storyBoardWithName:(NSString*)name bundle:(NSBundle*)bundle{
    UIStoryboard *storyBoard=[UIStoryboard storyboardWithName:name bundle:bundle];
    return storyBoard;
}

-(void)alertWithSure:(UIAlertAction*)sureAction cancel:(UIAlertAction*)cancelAction title:(NSString*)aTitle message:(NSString*)aMessage{
    UIAlertController * alertController = [UIAlertController alertControllerWithTitle:aTitle message:aMessage preferredStyle:UIAlertControllerStyleAlert];
    if (!cancelAction) {
        cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil];
    }
    if (!sureAction) {
        [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        }];
    }
    [alertController addAction:cancelAction];
    [alertController addAction:sureAction];
    [self presentViewController:alertController animated:YES completion:^{
        //
    }];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
